<template>
  <div id="UnionPay">
    <van-empty image="network" description="支付中如未跳转支付，请返回上一页或查看订单重新进行支付"></van-empty>
    <div class="flex-j-sa">
      <van-button plain type="info" @click="toBack" round style="width: 140px;" color="var(--themeBaseColor)">返回上一页</van-button>
      <van-button type="primary" round  @click="getOrderDetail" style="width: 140px;" color="var(--themeBaseColor)">查看订单</van-button>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {};
  },
  activated() {
    this.getData();
  },
  methods: {
    getData() {
      $http.get("order.merge-pay.converge-union-pay", { order_pay_id: this.$route.params.payid,child_pay_id: this.$route.query.child_pay_id || 0 }, "").then(response => {
        if (response.result == 1) {
          if (this.fun.isCPS() && this.fun.isCPSAPPI()) {
            let json = response.data.data;
            if (this.fun.isIosOrAndroid() === "ios") {
              unionPayIOS({ body: "cuPayIOS", json: JSON.stringify(json) });
            } else {
              unionPayAndroid(JSON.stringify(json));
            }
            return;
          }
          const div = document.createElement("div");
          div.innerHTML = response.data.data.rc_Result;
          document.body.append(div);
          document.forms[0].submit();
        } else {
          this.$dialog
            .alert({
              message: response.msg
            })
            .then(() => {
              this.$router.push(this.fun.getUrl("member", {}));
            });
        }
      });
    },
    toBack() {
      if (window.history.length <= 1) {
        if (window.isMiniprogram) {
          // 小程序端跳转对应页面
          return wx.miniProgram.navigateBack({ delta: 1 });
        }
        if (this.fun.isWindVane()) {
          let params = { animation:true };
          window.WindVane.call('SBase','navigationBack',params,function(e){
            console.log('navigationBack success:'+JSON.stringify(e));
          },function(e){
            console.log('navigationBack failure:'+JSON.stringify(e));
          });
          return;
        }
        this.$router.push(this.fun.getUrl("home", {}));
      }else {
        this.$router.go(-1);
      }
    },
    getOrderDetail() {
      this.$router.replace(this.fun.getUrl("member"));
    }
  }
};
</script>
<style lang="scss" scoped>
</style>